package cate.game.client.interceptor;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.MsgInput;
import cate.game.log.GameLoggerFactory;
import org.slf4j.Logger;

public class CommandInvoker extends AbstractCommandInterceptor{
    @Override
    public void execute(MsgInput msgInput, GameBody gameBody, ClientContext clientContext) {
        try {
            msgInput.execute(gameBody, clientContext);
        } catch (Exception e) {
            Logger logger = GameLoggerFactory.getLogger(gameBody, CommandInvoker.class);
            logger.error("{}请求{} 异常", clientContext.getRole() == null ? "":clientContext.getRole().getBase().name, msgInput.getClass(), e);
        }
    }

    @Override
    public CommandInterceptor getNext() {
        return null;
    }

    @Override
    public void setNext(CommandInterceptor next){
        throw new UnsupportedOperationException("CommandInvoker必须最后添加");
    }
}
